ALMaSS  1.0
The Animal, Landscape and Man Simulation System
Crop Class Reference

The base class for all crops. More...

#include <farm.h>

Public Member Functions

virtual ~Crop ()
 
 Crop ()
 
int GetFirstDate (void)
 
virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
int GetCropClassification ()
 
void SetCropClassification (int a_classification)
 

Protected Member Functions

void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
void SimpleEvent_ (long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
 Adds an event to this crop management without relying on member variables. More...
 

Protected Attributes

Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Detailed Description

The base class for all crops.

Constructor & Destructor Documentation

◆ ~Crop()

virtual Crop::~Crop ( )
inlinevirtual
560 {}

◆ Crop()

Crop::Crop ( )
298 {
299  m_ddegstoharvest = -1; // Set to -1 to indicate that this is not using ddegs to harvest, this will be reset in descendent classes as needed
300  SetCropClassification(tocc_Winter); // Defualt classification is Winter - change this if necessary in the derived crop constructor
301 }
int m_ddegstoharvest
Definition: farm.h:543
void SetCropClassification(int a_classification)
Definition: farm.h:569
@ tocc_Winter
Definition: farm.h:214

References tocc_Winter.

Member Function Documentation

◆ ChooseNextCrop()

void Crop::ChooseNextCrop ( int  a_no_dates)

Chooses the next crop to grow in a field.

The function finds the next crop to grow on a field where the current crop's management has finished. If necessary, it adjusts current crop's management to the new crop.

318  {
319 
323  if(cfg_OptimisingFarms.value()){ // do this only if we have optimising farms
324  if(!cfg_OptimiseBedriftsmodelCrops.value()){ // do this only if we use almass crops!!
325 
326  if (g_date->GetYearNumber()>0){ //changed 030713 since we dont use m_rotation anymore - but we do in the hidden year!
327  OptimisingFarm * opf;
328  if(m_farm->GetType() == tof_OptimisingFarm){ //take only optimising farms
329  opf = dynamic_cast<OptimisingFarm*>(m_farm);
331  //move MDates if necessary, use the new_startdate:
332  if (m_ev->m_startday > g_date->DayInYear(1,7)) {
333  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
334  {
335  g_msg->Warn( WARN_BUG, "Crop::ChooseNextCrop(): ","Harvest too late for the next crop to start!!!" );
336  exit( 1 );
337  }
338  // Now fix any late finishing problems
339  for (int i=0; i<a_no_dates; i++) {
340  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
341  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
342  }
343  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
344  m_field->SetMConstants(i,0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
345  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
346  }
347  }
348  }
349 
350  }
351  }
352  }
353  }
354 
355 }
class Calendar * g_date
Definition: calendar.cpp:38
int GetYearNumber(void)
Definition: calendar.h:68
int DayInYear(void)
Definition: calendar.h:58
bool value(void)
Definition: configurator.h:135
FarmEvent * m_ev
Definition: farm.h:539
Farm * m_farm
Definition: farm.h:537
LE * m_field
Definition: farm.h:538
TTypesOfFarm GetType(void)
Definition: farm.h:901
int GetMDates(int a, int b)
Definition: elements.h:341
void SetMConstants(int a, int c)
Definition: elements.h:344
void SetMDates(int a, int b, int c)
Definition: elements.h:342
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:2029
void Match_crop_to_field(LE *a_field)
Finds a crop to be grown on a given field next year.
Definition: farm.cpp:9161
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
CfgBool cfg_OptimiseBedriftsmodelCrops("OPTIMISE_BEDRIFTSMODEL_CROPS", CFG_CUSTOM, false)
If set to true, the original farm optimisation model's crop set is used in the farmer decision making...
@ tof_OptimisingFarm
Definition: farm.h:273
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_BUG
Definition: maperrormsg.h:34
int m_startday
Definition: farm.h:466

References cfg_OptimiseBedriftsmodelCrops, cfg_OptimisingFarms, Calendar::DayInYear(), g_date, g_msg, Calendar::GetYearNumber(), OptimisingFarm::Match_crop_to_field(), tof_OptimisingFarm, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ Do()

bool Crop::Do ( Farm a_farm,
LE a_field,
FarmEvent a_ev 
)
virtual
303  {
304  return true;
305 }

◆ GetCropClassification()

int Crop::GetCropClassification ( )
inline
567 { return m_CropClassification; }
int m_CropClassification
Definition: farm.h:545

References m_CropClassification.

◆ GetFirstDate()

int Crop::GetFirstDate ( void  )
inline
562 { return m_first_date; }
int m_first_date
Definition: farm.h:540

References m_first_date.

◆ SetCropClassification()

void Crop::SetCropClassification ( int  a_classification)
inline
569 { m_CropClassification = a_classification; }

References m_CropClassification.

◆ SimpleEvent()

void Crop::SimpleEvent ( long  a_date,
int  a_todo,
bool  a_lock 
)
protected

Adds an event to this crop management.

307  {
308 
309  m_farm->AddNewEvent(m_field->GetVegType(), a_date, m_field, a_todo, m_field->GetRunNum(), a_lock, 0, false, (TTypesOfVegetation)0);
310 }
void AddNewEvent(TTypesOfVegetation a_event, long a_date, LE *a_field, int a_todo, long a_num, bool a_lock, int a_start, bool a_first_year, TTypesOfVegetation a_crop)
Adds an event to the event queue for a farm.
Definition: farm.cpp:789
long GetRunNum(void)
Definition: elements.h:117
virtual TTypesOfVegetation GetVegType(void)
Definition: elements.h:125
TTypesOfVegetation
Definition: tov_declaration.h:30

◆ SimpleEvent_()

void Crop::SimpleEvent_ ( long  a_date,
int  a_todo,
bool  a_lock,
Farm a_farm,
LE a_field 
)
protected

Adds an event to this crop management without relying on member variables.

312  {
313 
314  a_farm->AddNewEvent(a_field->GetVegType(), a_date, a_field, a_todo, a_field->GetRunNum(), a_lock, 0, false, (TTypesOfVegetation)0);
315 }

References Farm::AddNewEvent(), LE::GetRunNum(), and LE::GetVegType().

Member Data Documentation

◆ m_count

int Crop::m_count
protected

◆ m_CropClassification

int Crop::m_CropClassification
protected

◆ m_ddegstoharvest

int Crop::m_ddegstoharvest
protected

◆ m_ev

FarmEvent* Crop::m_ev
protected

◆ m_farm

Farm* Crop::m_farm
protected

◆ m_field

LE* Crop::m_field
protected

◆ m_first_date

int Crop::m_first_date
protected

Referenced by GetFirstDate().

◆ m_last_date

int Crop::m_last_date
protected

The documentation for this class was generated from the following files: